fix(hub): case-insensitive email login (#1887)#1946
Open
BootstrapperSBL wants to merge 1 commit intohenrygd:mainfrom
Open
fix(hub): case-insensitive email login (#1887)#1946BootstrapperSBL wants to merge 1 commit intohenrygd:mainfrom
BootstrapperSBL wants to merge 1 commit intohenrygd:mainfrom
Conversation
Users who register with a mixed-case email (e.g. "Foo@bar.com") could not log in with a different casing because PocketBase's password auth performs an exact-match lookup on the email field. Normalize the email to lowercase on user/superuser create so stored values are canonical going forward, and fall back to a case-insensitive lookup in the OnRecordAuthWithPasswordRequest hook so accounts created before this fix can still authenticate regardless of the case used. Fixes henrygd#1887
Contributor
Author
|
Heads up: I just noticed @svenvg93 opened #1889 back on April 4 for the same issue. Missed it when I went scouting — sorry for the duplicate. The approach there is simpler (lowercase-on-write) and @henrygd raised the concern about legacy mixed-case accounts that this PR's COLLATE NOCASE fallback is meant to cover. Happy to close this one if you'd rather iterate on #1889. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Fixes #1887. Users who register with a mixed-case email (e.g.
Foo@bar.com) could not log in asfoo@bar.combecause PocketBase's password auth performs an exact-match lookup on the email field.Before
After
Same request succeeds regardless of the case used at login.
Approach
Two small hooks in the
userspackage:NormalizeEmailis bound toOnRecordCreatefor bothusersand_superusers. It lowercases the email before save so stored values are canonical going forward. The existing PocketBase unique email index then naturally rejects case-variant duplicates.ResolveAuthIdentityis bound toOnRecordAuthWithPasswordRequest. When PocketBase's exact-match lookup does not find a record, it falls back to[[email]] = {:email} COLLATE NOCASE. This covers accounts created on versions without the normalize hook.No DB schema change, no migration, nothing to break on existing installs. The fix is scoped to the auth path and stays within PocketBase's hook API.
Changelog
Fixed
usersand_superuserscollections. Fixes [Bug]: Login E-Mail is case Sensitive #1887.Changed
Tests
internal/hub/case_insensitive_email_test.goadds two test functions:TestEmailIsNormalizedOnCreate— verifies that freshly created users/superusers have their email persisted lowercase, and that a case-variant second registration is rejected by the unique index.TestCaseInsensitiveEmailLogin— simulates a legacy account whose email was stored mixed-case before this fix, then exercises the/auth-with-passwordendpoint forusersand_superuserswith lowercase, uppercase and original-case identities. Also covers the negative paths (wrong password, unknown email).All hub package tests pass. The pre-existing
agentandinternal/alertstest flakes onupstream/mainare unchanged by this PR.